<template>
  <!--before-close 关闭前的回调，会暂停 Dialog 的关闭.里面的回调函数用来关闭 Dialog -->
  <el-dialog
    v-model="props.visible"
    title="Shipping address"
    :before-close="close"
  >
    <el-form :model="form">
      <el-form-item label="Promotion name" :label-width="formLabelWidth">
        <el-input v-model="form.name" autocomplete="off" />
      </el-form-item>
      <el-form-item label="Zones" :label-width="formLabelWidth">
        <el-select v-model="form.region" placeholder="Please select a zone">
          <el-option label="Zone No.1" value="shanghai" />
          <el-option label="Zone No.2" value="beijing" />
        </el-select>
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="modify"> 确定 </el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, toRefs, defineProps, defineEmits } from 'vue'
const state = reactive({
  // dialogFormVisible: false,
  form: {
    name: '',
    region: '',
  },
  formLabelWidth: '120px',
})
const { form, formLabelWidth } = toRefs(state)

const props = defineProps<{
  visible: boolean
}>()

const emit = defineEmits(['close'])
// 取消，传递给父组件
const close = () => {
  emit('close')
}
// 确定
const modify = () => {
  close()
}
</script>

<style scoped lang="scss"></style>
